$(document).ready(function() {

    // $("#scroll-vertical-datatable").DataTable({
    //     // 'searching':false,
    //     // 'bFilter':false,
    //     // info:false,
    //     "order": []
    //     // "bSort":false
    // });


    tableSet();
    $("#customerList").change(function(){

        let selectedOption = $('#customerList option:selected').text();
        let profitInfo = {
            customerName: selectedOption,
            updateFlg: '1'
        }
        $.ajax({
            type: "post",
            url:"/profitList/init",
            cache: false,
            data: profitInfo,
            success: function (data) {
                $("#tableUpdate").html(data);
                tableSet();
            },
            complete: function () {

            },
            error: function(res) {
                toastr.clear();
                toastr.error('数据更新失败！');
            }
        });
    });

});


function openDialog() {
    let myDialog = document.querySelector("#myDialog");

    myDialog.showModal();
}

function closeDialog() {
    let myDialog = document.querySelector("#myDialog");
    $('#customerPay').val(null);
    myDialog.close();
}

function submitPay() {
    let customerPay = $('#customerPay').val();
    let dialogCustomerValue = $('#dialogCustomerList option:selected').val();
    let dialogCustomerText = $('#dialogCustomerList option:selected').text();

    let profitInfo = {
        profitPay: customerPay,
        customerId: dialogCustomerValue,
        customerName: dialogCustomerText
    }

    $.ajax({
        type: "post",
        url:"/profitList/insertProfitInfo",
        cache: false,
        data: profitInfo,
        dataType:'json',
        success: function (res) {

            toastr.clear();
            toastr.success('金额录入成功！');
            $('#customerPay').val(null);
            $("#dialogCustomerList").val('0');

            setTimeout(function () {
                document.querySelector("#myDialog").close();
                window.location.href='/profitList/init';
            },500);
        },
        complete: function () {

        },
        error: function(res) {
            toastr.clear();
            toastr.error('录入失败，检查录入数据是否正确！');
        }
    });

}

function callOrder(para) {

    let orderId = para.id;
    let map = new Map();
    map.set("orderId", orderId);
    map.set("readOnlyFlg", "1");

    let url = "/orderEnter/init";
    post(map, url);
}

function post(paramsMap, url) {
    var temp_form = document.createElement("form");
    temp_form.action = url;
    temp_form.target = "_self";
    temp_form.method = "post";
    temp_form.style.display = "none";

    for (let[key, value] of paramsMap) {
        let tempInput = document.createElement("input");
        tempInput.type = "hidden";
        tempInput.name = key;
        tempInput.value = value;
        temp_form.appendChild(tempInput);
    }

    document.body.appendChild(temp_form);
    temp_form.submit();
    document.body.remove(temp_form[0]);
}

function tableSet() {
    $('#listTable').DataTable( {
        "scrollY":        "525px", // 设置垂直滚动区域高度
        "scrollCollapse": true,    // 当表格数据不足一页时，滚动条会自动折叠
        "paging":         false,   // 禁用分页
        // "scrollX":        true,    // 开启水平滚动条
        // "scrollXInner":   "100%",  // 水平滚动区域宽度
        "bSort": false, // 禁用排序功能
        "bInfo": false,  // 禁用显示记录数信息
        "bFilter": false  // 禁用右上角搜索框

    } );
}
